package zxj.spay.modular.user.ctrl;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import zxj.spay.anotation.NoAccess;
import zxj.spay.base.Result;
import zxj.spay.base.resource.SessionName;
import zxj.spay.entity.User;
import zxj.spay.modular.user.service.UserService;

/**
 * 登陆登出的contoller
 * @author 朱小杰
 *
 */
@Controller
@RequestMapping("/user")
public class UserCtrl {
	public final static Logger LOG = Logger.getLogger(UserCtrl.class);
	@Resource
	private UserService userService;

	/**
	 * 首页
	 * @return
	 */
	@NoAccess
	@RequestMapping("/index.htm")
	public String index(){
		return "/WEB-INF/view/index.ftl";
	}
	
	/**
	 * 执行登陆操作
	 * @return
	 */
	@NoAccess
	@ResponseBody
	@RequestMapping("login.ajax")
	public Result login(User user,HttpServletRequest request){
		return userService.login(user,request);
	}
	
	/**
	 * 注销登陆
	 * @param request
	 * @return
	 */
	@RequestMapping("/logOut.htm")
	public String logOut(HttpServletRequest request){
		request.getSession().removeAttribute(SessionName.USER);
		return "redirect:/";
	}
	

}
